package com.spzx.product.api.factory;

import com.spzx.common.core.domain.R;
import com.spzx.product.api.RemoteCategoryService;
import com.spzx.product.api.domain.Category;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class RemoteCategoryServiceFactory implements FallbackFactory<RemoteCategoryService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteCategoryServiceFactory.class);

    @Override
    public RemoteCategoryService create(Throwable cause) {
        log.error("商品服务调用失败:{}", cause.getMessage());
        return new RemoteCategoryService() {
            @Override
            public R<List<Category>> listIndexCates()  {
                return  R.fail("获取分类数据失败:" + cause.getMessage());
            }

            @Override
            public R<List<Category>> listCateTree() {
                return R.fail("获取 分类页数据嵌套失败:" + cause.getMessage());
            }


        };
    }
}
